package com.zhongyu.controller;

import com.zhongyu.pojo.Order;
import com.zhongyu.pojo.User;
import com.zhongyu.service.ShenHemAPPERService;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/caiGou/shenhe/")
public class ShenHemController {

    @Resource
    private ShenHemAPPERService shenHemAPPERService;

    @GetMapping("/search/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize){
        PageResult pageResult=shenHemAPPERService.searchAll(pageNo, pageSize);
        return ResultVo.success(pageResult);
    }

    @GetMapping("/update")//post请求要加@RequestBody进行接收
    public ResultVo update(Order order, HttpSession session) {
        try {
           LocalDateTime localDateTime=order.setCheckTime(LocalDateTime.now());
           String state= order.setState(Order.STATE_CHECK);
            User loginUser= (User) session.getAttribute("loginUser");
            Integer id=order.getId();
            Integer shenhe=loginUser.getId();
            shenHemAPPERService.update(state,localDateTime,id,shenhe);
            return ResultVo.success("审核成功");
        } catch (Exception ex) {
            return ResultVo.failure("审核失败", ex);
        }

    }


}
